using System;
using System.IO;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using Microsoft.Practices.RecipeFramework;
using Config = System.Configuration.Configuration;
using EnvDTE;
using System.ComponentModel.Design;
using Microsoft.Practices.RepositoryFactory.CommonHelpers;
using Microsoft.Practices.ComponentModel;

namespace Microsoft.Practices.RepositoryFactory.Actions.Configuration
{
    /// <summary>
    /// Saves any changes to a Configuration object
    /// </summary>
    [ServiceDependency(typeof(DTE))]
    public sealed class SaveConfigurationAction : Microsoft.Practices.RecipeFramework.Action
    {
        #region Input Properties

        /// <summary>
        /// The configuration object to Save
        /// </summary>
        [Input(Required=true)]
        public Config Configuration
        {
            get { return configuration; }
            set { configuration = value; }
        } Config configuration;

        #endregion

        #region Output Properties

        #endregion

        #region Action members

        /// <summary>
        /// <see cref="IAction.Execute"/>
        /// </summary>
        public override void Execute()
        {
            DTE vs = GetService<DTE>(true);
            TFSHelper.CheckOutFile(vs, this.configuration.FilePath);
            this.Configuration.Save(ConfigurationSaveMode.Modified);
        }

        /// <summary>
        /// <see cref="IAction.Undo"/>
        /// </summary>
        public override void Undo()
        {
        }

        #endregion
    }
}

